
package com.huizhan.web.dao;
 
import org.springframework.data.domain.*;
import org.springframework.data.jpa.repository.*;
import org.springframework.stereotype.Repository;
import com.huizhan.web.model.*;

@Repository 
public interface ProjectAvatarDao extends JpaRepository<ProjectAvatar,Long>
{
    /**
     * 根据类型id删除头像
     * @param documentTypeId
     */
    void deleteByDocumentTypeId(Long documentTypeId);

    /**
     * 根据类型id删除头像
     * @param ticketTypeId
     */
    void deleteByTicketTypeId(Long ticketTypeId);

    /**
     * 分页查头像记录集合
     * @param name 名称
     * @param code 码值
     * @param document_Type_Id 证件类型ID
     * @param project_Id 项目ID
     * @param ticket_Type_Id 票类型
     * @param pageable 分页参数
     * @return 赠票记录集合
     */
    @Query(
        value = "SELECT * FROM project_avatar"
            + " WHERE (name LIKE CONCAT('%',?1,'%') OR ?1  = '')"
            + " AND (code LIKE CONCAT('%',?2,'%') OR ?2  = '' )"
            + " AND (project_Id =?3 OR ?3  = '') "
            + " AND (document_Type_Id =?4 OR ?4 = 0 )"
            + " AND (ticket_Type_Id = ?5 OR ?5 = 0 )", 
        countQuery = "SELECT COUNT(1) FROM project_avatar"
            + " WHERE (name LIKE CONCAT('%',?1,'%') OR ?1  = '')"
            + " AND (code LIKE CONCAT('%',?2,'%') OR ?2  = '' )"
            + " AND (project_Id =?3 OR ?3  = '') "
            + " AND (document_Type_Id =?4 OR ?4 = 0 )"
            + " AND (ticket_Type_Id = ?5 OR ?5 = 0)",
        nativeQuery = true
    )
    Page<ProjectAvatar> findByWhere(String name,String code, String project_Id,Long document_Type_Id,Long ticket_Type_Id, Pageable  pageable);
}
